package com.complaint.dao.impl;

import com.complaint.dao.BaseDAO;
import com.complaint.dao.ComplaintDAO;
import com.complaint.pojo.Complaint;
import com.complaint.pojo.User;

import java.util.List;

public class ComplaintDAOImpl extends BaseDAO implements ComplaintDAO {
    public int addComp(Complaint complaint) {
        String sql = "insert into complaintTable values(DEFAULT,?,?,?,?,?,?,?)";
        return update(sql,
                complaint.getTitle(),
                complaint.getUserId(),
                complaint.getComplaining(),
                complaint.getComplained(),
                complaint.getContent(),
                complaint.isHidden(),
                complaint.getStatus()
                );
    }

    public int statusComp(String id, String status) {
        String sql = "update complaintTable set status=? where id=?";
        return update(sql, status, id);
    }

    public int blackComp(String id) {
        String sql = "delete from complaintTable where id=?";
        return update(sql, id);
    }

    @Override
    public List<User> recordUser() {
        String sql = "select id, name from userTable";
        return sQuery(User.class, sql);
    }
}
